/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myBeans;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MrMAD
 */
public class Customer {

    String name;
    String password;
    String email;
    String phone;
    String address;
    String company;

    public Customer() {
    }

    public Customer(String name, String password, String email, String phone, String address, String company) {
        this.name = name;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.address = address;
        this.company = company;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Connection getConnection() throws ClassNotFoundException, SQLException {
        String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=Customer;user=sa;password=sa";
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection con = DriverManager.getConnection(connectionUrl);
        return con;
    }

    public boolean authenticate(String inputName, String inputPass) {
        boolean isValid = false;
        try {
            Connection con = this.getConnection();
            String sqlString = "SELECT * FROM Customer WHERE name = '" + inputName + "'";
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(sqlString);
            String storedPass = "";
            while(rs.next()){
                 storedPass = rs.getString("password");
            }
            isValid = inputPass.equals(storedPass);

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            return isValid;
        }
    }
}
